package com.weslide.weslideapp.receiver;

import com.weslide.weslideapp.activity.UnlockActivity;

import android.app.KeyguardManager;
import android.app.KeyguardManager.OnKeyguardExitResult;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.CountDownTimer;
import android.util.Log;

public class BootBroadCastReceiver extends BroadcastReceiver {
	private static final String TAG = "BootBroadCastReceiver";
	public static final String ACTION = "android.intent.action.BOOT_COMPLETED";
	public static final String ACTION_LOCK_SCREEN = "action_lock_screen";
	private MyCountDown countDown = new MyCountDown(1000, 200);
	private Context mContext;

	@Override
	public void onReceive(Context context, Intent intent) {
		Log.i(TAG, "onReceive");
		mContext = context;
		if (intent.getAction().equals(ACTION)) {
			Intent mIntent = new Intent();
			mIntent.setAction("com.weslide.weslideapp.service.MyService");
			Log.i(TAG, ACTION);
			context.startService(mIntent);
		}
		if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)
				|| intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
			Log.i(TAG, ACTION_LOCK_SCREEN);
			toUnlock(mContext);
			// countDown.start();
		}
	}

	public void toUnlock(Context context) {
		Intent intent1 = new Intent(context, UnlockActivity.class);
		intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent1);
	}

	class MyCountDown extends CountDownTimer {

		public MyCountDown(long millisInFuture, long countDownInterval) {
			super(millisInFuture, countDownInterval);
		}

		@Override
		public void onTick(long millisUntilFinished) {

		}

		@Override
		public void onFinish() {
			toUnlock(mContext);
		}
	}
}
